﻿using AntMovement.Core;
using AntMovement.Core.IParameter;
using AntMovement.Parameter;
using AntMovement.Views;
using Prism.Ioc;
using Prism.Modularity;
using System.IO;
using System;
using System.Windows;
using AntMovement.Core.Manager;
using AntMovement.Domain;
using System.Diagnostics;

namespace AntMovement
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        protected override Window CreateShell()
        {
            var device_path = $"{Environment.CurrentDirectory}\\init";
            if (!Directory.Exists(device_path))
            {
                Directory.CreateDirectory(device_path);
            }
            int count = Process.GetProcessesByName(System.Reflection.Assembly.GetEntryAssembly().FullName.Split(',')[0]).Length;
            if (count > 1)
            {
                _ = MessageBox.Show($"不可以重复打开软件！！！" , "蚂蚁运动");
                Current.Shutdown();
            }
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<IHoldParameter, HoldParameter>();
            containerRegistry.RegisterSingleton<ITemporaryParameter, TemporaryParameter>();
            containerRegistry.RegisterSingleton<ILog, AntMovementLog>();
            containerRegistry.RegisterSingleton<IIOParameter, IOParameter>();
            containerRegistry.RegisterSingleton<IAxisParameter, AxisParameter>();
            containerRegistry.RegisterSingleton<IDialogHost, Domain.DialogStarryEdge>();
            containerRegistry.RegisterSingleton<ITaskManager, TaskManager>();
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            moduleCatalog.AddModule<AntMovement.Menu.Device.DeviceModule>();
            moduleCatalog.AddModule<AntMovement.Custom.Domain.CustomModule>();
            moduleCatalog.AddModule<AntMovement.Menu.HardControl.HardControlModule>();
            //moduleCatalog.AddModule<StarryEdge.Menu.SettingSystem.SettingSystemModule>();
            //moduleCatalog.AddModule<StarryEdge.Menu.Device.DeviceModule>();
            moduleCatalog.AddModule<AntMovement.Menu.LogSystem.LogSystemModule>();
        }

    }
}
